<?php
declare(strict_types=1);

namespace App\Console\Commands\Tasks;


use App\Exceptions\BasicException;
use App\Repositories\BlindBox\ExchangeRepository;
use Illuminate\Console\Command;

class ScriptPetSeasonCommand extends Command
{

    protected $signature = 'script:fixPetUserSeason';
    protected $description = '修复盲盒礼物兑换';

    public function __construct()
    {
        parent::__construct();
    }


    public function handle()
    {
        $userRecordList = app("model_lottery_pet_pool_draw_record")->selectRaw('sum(count) as count, user_id')
            ->where('created_at', '>=', '2022-08-05 10:30:00')
            ->where('gift_type', 2)->groupBy("user_id")->get();

        $season = "20220730000001";
        foreach($userRecordList as $record) {
            $userSeasonRecord       = app('model_lottery_pet_user_season_record')->firstOrCreate([
                "user_id" => $record->user_id,
                "season"  => $season,
            ]);
            $userSeasonRecord->prop_count = $record->count;
            $userSeasonRecord->save();
        }
    }
}